package lab.gene.service.impl;

import java.util.Date;
import java.util.List;

import lab.gene.pojo.Gene;
import lab.gene.pojo.GenePrepIntermediates;
import lab.gene.dao.GeneDAO;
import lab.gene.dao.GenePrepIntermediatesDAO;
import lab.gene.service.GenePrepIntermediatesService;
import lab.user.dao.UserDAO;
import lab.user.pojo.User;

public class GenePrepIntermediatesServiceImpl implements
		GenePrepIntermediatesService {

	@Override
	public GenePrepIntermediates getGenePrepIntermediatesByNameAndType(
			String geneName, String type) {
		// TODO Auto-generated method stub
		GenePrepIntermediatesDAO dao = new GenePrepIntermediatesDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		GenePrepIntermediates result = dao.getGenePrepIntermediatesByNameAndType(g, type);		
		return result;
	}

	@Override
	public void addGenePrepIntermediates(String geneName, String type, Date recordDate1, Date recordDate2, 
			String pcrX1, String pcrY1, String pcrZ1, 
			String pcrX2, String pcrY2, String pcrZ2, 
			int x1, int x2, int y1, int y2, int z1,
			int z2, String checked, String repeatChecked, String userName) {
		// TODO Auto-generated method stub
		UserDAO udao = new UserDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		User u = udao.getUser(userName);
		GenePrepIntermediatesDAO dao = new GenePrepIntermediatesDAO();
		GenePrepIntermediates gi = new GenePrepIntermediates();
		gi.setChecked(checked);
		gi.setDate1(recordDate1);
		gi.setDate2(recordDate2);
		gi.setDateModified(new Date());
		gi.setGene(g);
		gi.setPcrX1(pcrX1);
		gi.setPcrX2(pcrX2);
		gi.setPcrY1(pcrY1);
		gi.setPcrY2(pcrY2);
		gi.setPcrZ1(pcrZ1);
		gi.setPcrZ2(pcrZ2);
		gi.setRepeatChecked(repeatChecked);
		gi.setType(type);
		gi.setUser(u);
		gi.setX1(x1);
		gi.setX2(x2);
		gi.setY1(y1);
		gi.setY2(y2);
		gi.setZ1(z1);
		gi.setZ2(z2);
		System.out.println("Adding here!");
		dao.addGenePrepIntermediates(gi);
	}
	
	@Override
	public List<GenePrepIntermediates> getGenePrepIntermediatesHistory(String geneName, String type) {
		// TODO Auto-generated method stub
		
		List<GenePrepIntermediates> g = null;
		GeneDAO gdao = new GeneDAO();
		Gene gene = gdao.getGene(geneName);
		GenePrepIntermediatesDAO dao = new GenePrepIntermediatesDAO();
		g = dao.getGenePrepIntermediatesHistory(gene, type);
		return g;

	}

}
